
Option Explicit

Dim doc
Set doc = application.ActiveDocument
main

' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

sub GetUserLicence(docObj)

	If ValidateServer(docObj) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	
end sub

'----------------------------------------------------------------

sub UserDisplayCotrol(docObj)
	Dim ischeck
	ischeck = docObj.ActiveView.DisplayControl.PartItems (epcbDCSilkscreenRefDes,epcbSideBottom   )
	ischeck = not ischeck
	docObj.ActiveView.DisplayControl.PartItems (epcbDCSilkscreenRefDes,epcbSideBottom  ) = ischeck
end sub

'----------------------------------------------------------------
sub main()
	GetUserLicence(doc)
	UserDisplayCotrol(doc)
end sub
'----------------------------------------------------------------

